#ifndef _IOSTREAMBASE_H_
#define _IOSTREAMBASE_H_

#include "ioeventdef.h"
#include "iotcpbase.h"

uvNameSpaceBegin

#define		STREAM_EVENT_EOF			0x01
#define		STREAM_EVENT_TIMEOUT		0x02
#define		STREAM_EVENT_ERROR			0x04
#define		STREAM_EVENT_UNKNOWN		0x80

#define		STREAM_READ					0x20
#define		STREAM_WRITE				0x40

#define		STREAM_READING				0x20
#define		STREAM_WRITEING				0x40

struct io_streambase_t {
	io_data	io;
	struct event* ev;
	struct bufferevent *bev;
	struct evbuffer * input;
	struct evbuffer * output;
	short	writealive;
	short	readlive;
	short	state;
	bool	thread;
	void(*stream_fun_writecb)(io_streambase_t *pData, unsigned long ulen);
	void(*stream_fun_readcb)(io_streambase_t *pData, unsigned long ulen);
	void(*stream_fun_eventcb)(io_streambase_t *pData, short what);
};

int	io_streambase_init(io_streambase_t* pStream, io_tcp_i* pTcp, int iReadTimeOut, int iWriteTimeOut);
int	io_streambase_read_timeout(io_streambase_t* pStream, int iReadTimeOut);
int	io_streambase_wrtie_timeout(io_streambase_t* pStream, int iWriteTimeOut);
int	io_streambase_write(io_streambase_t* pStream, unsigned long ulMinSize);
int	io_streambase_read(io_streambase_t* pStream, unsigned long ulMinSize);
int	io_streambase_read_some(io_streambase_t* pStream);
int	io_streambase_write_some(io_streambase_t* pStream);
int	io_streambase_close(io_streambase_t* pStream);

uvNameSpaceEnd

#endif
